package com.virtualCat.dao;

import com.virtualCat.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderDao {
    @Insert("insert into t_order(orderid,openid,catid,datetime,price,receiver,phone,area,build_number,cname,gname,gimg,status)" +
            "values(#{orderid},#{openid},#{catid},#{datetime},#{price},#{receiver},#{phone},#{area},#{build_number},#{cname},#{gname},#{gimg},#{status})")
    int insertOrder(Order order);

    /**
     * 根据openid查询我的界面信息
     */
    @Select("select count(1) from t_order where openid=#{openid} and status=#{status} ")
    int mineInfo(@Param("openid") String openid,@Param("status") int status);

    /**
     * 根据openid和status查询订单数量
     *
     */
    @Select("select count(1) from t_order where openid=#{openid} and status=#{status} ")
    int queryOrderNumber(@Param("openid") String openid,@Param("status") int status);

    /**
     * 根据订单状态(Status)查询订单详情
     *
     */
    @Select("select orderid,openid,catid,datetime,price,receiver,phone,area,build_number,cname,gname,gimg,status from t_order where status=#{status} and openid=#{openid}")
    @Results(
            @Result(column="build_number",property="build_number")
    )
    List<Order> findOrderByStatus(@Param("openid") String openid, @Param("status") int status);

    /**
     * 根据订单id(orderid)查询订单详情
     *
     */
    @Select("select orderid,openid,catid,datetime,price,receiver,phone,area,build_number,cname,gname,gimg,status from t_order where orderid=#{orderid}")
    @Results(
            @Result(column="build_number",property="build_number")
    )
    Order findOrderByOrderid(@Param("orderid")String orderId);


    /**
     * 确认收货
     */
    @Update("update t_order set status=2 where orderid=#{orderid}")
    int updateOrder(@Param("orderid")String orderId);


}
